import { getKey, removeKey } from "@/utils/common/localStorage";
import { defineStore } from "pinia";
import {ref} from 'vue'
const userinfoResult=getKey('userinfoResult')

export const useUserStore=defineStore('user',()=>{
    const userInfo=ref({
        account:userinfoResult.account||'',
        name:userinfoResult.name||'',
        imageUrl:userinfoResult.imageUrl||'', 
        identity:userinfoResult.identity||'',
        email:userinfoResult.email||'',
        department:userinfoResult.department||'',
        sex:userinfoResult.sex||'',
        status:userinfoResult.status||'',
        create_time:userinfoResult.create_time||'',
        update_time:userinfoResult.update_time||'',
    })

    function clearUserInfo(){
        userInfo.value={
            account:'',
            name:'',
            imageUrl:'', 
            identity:'',
            email:'',
            department:'',
            sex:'',
            status:'',
            create_time:'',
            update_time:'',
        }
        removeKey('token')
    }
    
    const token=ref('')
    
    return {userInfo,token,clearUserInfo}
    
})